﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#include "GbmpCADScaleDlg.h"
#include <QDialog>
#include <QDoubleValidator>
#include <QToolTip>
#include "GbmpNew.h"
#include "GbmpConstants.h"

#include "EnableCompileWarning_The_LAST_IncludeInCpp.h"

GbmpCADScaleSettingDlg::GbmpCADScaleSettingDlg(QWidget* parent /*= nullptr*/) :QDialog(parent), m_dRealSize(0.0)
{
    m_ui.setupUi(this);

    QDoubleValidator *pDoubleValidator = NEW_AS_QT_CHILD(QDoubleValidator, this);
    DBG_WARN_AND_RETURN_VOID_UNLESS(nullptr != pDoubleValidator, L"pDoubleValidator为空",L"GDMPLab",L"2024-03-30");
    pDoubleValidator->setBottom(0.01);
    pDoubleValidator->setDecimals(2);
    m_ui.lineEdit->setValidator(pDoubleValidator);

    connect(m_ui.okButton, SIGNAL(clicked()), this, SLOT(OnApply()));
}

GbmpCADScaleSettingDlg::~GbmpCADScaleSettingDlg()
{

}

double GbmpCADScaleSettingDlg::GetRealSize() const
{
    return m_dRealSize;
}

void GbmpCADScaleSettingDlg::OnApply()
{
    bool bSuc = false;
    double dSize = m_ui.lineEdit->text().toDouble(&bSuc);

    if (!bSuc)
        return;

    if (dSize < gcmp::Constants::LENGTH_EPS)
    {
        m_ui.lineEdit->selectAll();
        QToolTip::showText(m_ui.lineEdit->mapToGlobal(QPoint()), QString::fromStdWString(GBMP_TR(L"请输入合理尺寸值")));
        return;
    }

    m_dRealSize = dSize;
    QDialog::accept();
}